<template>
 <div class="list" ref="wrapper">
     <div>
        <div class="area">
            <div class="title border-topbottom">当前城市</div>
            <div class="btn-list">
                <div class="btn-wrap">
                    <div class="btn">
                        {{this.currentCity}}
                    </div>
                </div>
               
            </div>
        </div >
        <div class="area">
            <div class="title border-topbottom">热门城市</div>
            <div class="btn-list">
                <div class="btn-wrap" v-for="item of hotCities" :key="item.id" @click="cityBtn(item.name)">
                    <div class="btn">
                        {{item.name}}
                    </div>
                </div>
               
            </div>
        </div>
        <div class="area" v-for="(item,key) of cities" :key="key" :ref="key">
            <div class="title border-topbottom">{{key}}</div>
            <div class="item-list" v-for="innnerItem of item":key="item.id"  @click="cityBtn(innnerItem.name)">
                <div class="item border-bottom">{{innnerItem.name}}</div> 
            </div>
            
        </div>
      
       
     </div>

 </div>
</template>
<script>
 import Bscroll from 'better-scroll'
 import {mapState,mapMutations} from "vuex"
 export default {
   props:{
       cities:Object,
       hotCities:Array,
       letter:String
   },
   data () {
     return {
     }
   },
   computed:{
       ...mapState({
           currentCity:'city'
       })
   },
   watch:{
       letter(e){
           if(e){
               const el=this.$refs[e][0]
               this.scroll.scrollToElement(el)
           }
       }
   },
   methods:{
       ...mapMutations(['changeCity']),
       cityBtn(city){
          this.changeCity(city)
           this.$router.push("/")
       }
       
   },
   mounted(){
     this.scroll=new Bscroll(this.$refs.wrapper)
   },
   components: {
   }
 }
</script>
<style lang="stylus" scoped>
    @import "~styles/varibles.styl"
    .border-topbottom
        &:before
            border-color #ccc
        &:after
            border-color #ccc
     .border-bottom
        &:before
            border-color #ccc
    .list
        position absolute
        top 1.58rem
        left 0
        right 0
        bottom 0
        overflow hidden
        .title
            height .54rem
            line-height 0.54rem
            color #666
            background #eee
            font-size .32rem
            padding-left .2rem
        .btn-list
            overflow hidden
            padding .1rem .6rem .1rem 0
            .btn-wrap
                width 33.33%
                float left
                .btn 
                    margin .1rem
                    padding .1rem 0
                    border .02rem solid #cccccc
                    text-align center
                    border-radius .06rem
        .item-list
            .item
                line-height 0.76rem
                padding-left 0.2rem
            

</style>

